Android Product Flavor 配置

這篇待看 Android常用的Gradle配置和加速编译

這篇講得挺不錯的 Squeezing your Gradle builds,摘錄其中一些 code

目前閱讀到一半左右

demo project

/variants.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ext {

basePackageName = 'saulmm.gradlestuff'
resAppColorName = 'build_brand_primary'
resAppName = 'build_app_name'
fieldShowAds = 'ADS'


paid = [

packageName : "${basePackageName}.premium",
appName : "Gradle Stuff Premium",
appColor : "#F44336",
showAds : "false",
versionName : "2.3.2",
versionCode : 4
]
}
/build.gradle
1
apply from: 'variants.gradle'
/{android module}/build.gradle
1
2
3
4
5
6
7
8
9
10
productFlavors {
paid {
def paid = rootProject.ext.paid

applicationId paid.packageName
buildConfigField 'boolean', fieldShowAds, paid.showAds
resValue 'string', resAppName, paid.appName
resValue 'color', resAppColorName, paid.appColor
}
}